package data;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import sprite.Button;
import sprite.Tower;

public class Sidebar extends JPanel{
	
	private static final long serialVersionUID = 1L;
	Button tower1, tower2, tower3;
	Rectangle bounds;
	Tower infoTower = new Tower();

	public Sidebar(Rectangle bounds) {
		this.bounds = bounds;
		tower1 = new Button(new ImageIcon("images/Black_up.png").getImage(), 840, 90);
		tower2 = new Button(new ImageIcon("images/Blue_up.png").getImage(), 910, 90);
		tower3 = new Button(new ImageIcon("images/Green_up.png").getImage(), 840, 160);
		
	}	
	public void drawOn(Graphics g) {
		
		g.setColor(Color.LIGHT_GRAY);
        g.fillRect(bounds.width-200, 0, 200, bounds.height);
        g.setColor(Color.BLACK);
        g.drawLine(bounds.width-200, 0, bounds.width-200, bounds.height);
		
        if (infoTower.getId() != -1) {
        	g.drawString("Power: " + infoTower.getPower(), 840, 220);
        }
        
        this.tower1.drawOn(g);
        this.tower2.drawOn(g);
        this.tower3.drawOn(g);
	}
	
	public int handleMousePressed(MouseEvent e, int mouseX, int mouseY) {
		if (tower1.getRect().contains(new Point(mouseX, mouseY))) {
			tower1.handleMousePressed(e, mouseX, mouseY);
			return 1;
		}
		else if (tower2.getRect().contains(new Point(mouseX, mouseY))) {
			tower2.handleMousePressed(e, mouseX, mouseY);
			return 2;
		}
		else if (tower3.getRect().contains(new Point(mouseX, mouseY))) {
			tower3.handleMousePressed(e, mouseX, mouseY);
			return 3;
		}
		else {
			return -1;
		}
		
	}
	public void drawInfo(Tower tower) {
		this.infoTower = tower;
	}

}
